package com.wxy.ej.flow.modules.taskflow.service.nodeExecuteStrategy.strategy.ui;

import com.alibaba.fastjson.JSONObject;
import com.rt.easyjava.common.base.Result;
import com.rt.easyjava.common.utils.others.StringUtils;
import com.wxy.ej.flow.modules.taskflow.dto.DataDto;
import com.wxy.ej.flow.modules.taskflow.dto.NodeDto;
import com.wxy.ej.flow.modules.taskflow.service.nodeExecuteStrategy.NodeStrategy;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UIOutDataNodeStrategy extends NodeStrategy {
    @Override
    public Result action(NodeDto node, JSONObject flowDataJson, DataDto dataDto) {
        // 输出数据的变量

        // list
        String uiStorageDataMapKeyVar = node.getDefineVarName();
        if (StringUtils.isNull(uiStorageDataMapKeyVar)) {
            return Result.builder();
        }
        Object dataObj = dataDto.getStorageDataVarMap().get(uiStorageDataMapKeyVar);
        dataDto.setUiOutData(dataObj);

        // total
        String defineVarName4PageTotal = node.getDefineVarName4PageTotal();
        if (StringUtils.isNull(defineVarName4PageTotal)) {
            return Result.builder();
        }
        Object dataObj1 = dataDto.getStorageDataVarMap().get(defineVarName4PageTotal);
        dataDto.setUiOutData4PageTotal(dataObj1);


        return Result.builder();
    }
}
